/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Precentacion.java
 *
 * Created on 25/06/2011, 10:43:57 AM
 */

package Vistas;

import Beans.Ciudad;
import Beans.Cliente;
import Beans.Pais;
import Beans.Proveedor;
import Beans.Provincia;
import Controladores.MUbicacion;
import Controladores.Mcliente;
import Imagenes.CtrlImagen;
import Vistas.Menu.Menu;
import com.birosoft.liquid.LiquidLookAndFeel;
import java.awt.Image;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;


/**
 *
 * @author Usuario
 */
public class VistaCliente extends javax.swing.JFrame {

      Mcliente Mc = new Mcliente();
      MUbicacion Mu = new MUbicacion();
      Cliente c=new Cliente();
      Cliente cl=new Cliente();
      Vector<Cliente> vc = new Vector<Cliente>();
      private DefaultTableModel modeloTabla1=new DefaultTableModel();
      int fila;
      String ced="vacio";
      boolean estado = false;
      boolean condicion = false; 
 

    /** Creates new form Precentacion */
    public VistaCliente() {
        initComponents();

        
    }

    public VistaCliente(Mcliente mc,MUbicacion Mu) {
          initComponents();
           this.Mc=mc;
           this.Mu=Mu;
           this.setResizable(false);
           jBtnFoto.setIcon(null);
            this.DesactivarCampos();    
            this.TablaPrincipal();
            this.JcomboPais();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new CtrlImagen("/Imagenes/a1.jpg");
        jPanelTransparente5 = new Imagenes.JPanelTransparente();
        jCBCiudad = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTxaObs = new javax.swing.JTextArea();
        jLabel10 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jTxtNombre = new javax.swing.JTextField();
        jTcedula = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jCbxPais = new javax.swing.JComboBox();
        jLabel17 = new javax.swing.JLabel();
        jCbxProvincia = new javax.swing.JComboBox();
        jLabel19 = new javax.swing.JLabel();
        jLblFoto = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        jBtnFoto = new javax.swing.JButton();
        jTxtCelular = new javax.swing.JTextField();
        jTxtTelefono = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jTxtMail = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jTxDireccion = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jTxtApellido = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanelTransparente6 = new Imagenes.JPanelTransparente();
        jBSalir1 = new javax.swing.JButton();
        jBActualizar = new javax.swing.JButton();
        jBModificar = new javax.swing.JButton();
        jBEliminar = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        JBuscar = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Interfaz Control de Clientes");

        jTxaObs.setColumns(20);
        jTxaObs.setRows(5);
        jScrollPane1.setViewportView(jTxaObs);

        jLabel10.setText("Nº Telefono:");

        jLabel12.setText("*Cedula");

        jLabel13.setText("* Nombre:");

        jTxtNombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTxtNombreActionPerformed(evt);
            }
        });

        jLabel14.setText("* Nº Celular:");

        jLabel16.setText("Pais");

        jCbxPais.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCbxPaisActionPerformed(evt);
            }
        });

        jLabel17.setText("Provincia");

        jCbxProvincia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCbxProvinciaActionPerformed(evt);
            }
        });

        jLabel19.setText("Ciudad");

        jLblFoto.setBackground(new java.awt.Color(255, 255, 204));

        jLabel22.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel22.setText("Detalle");

        jBtnFoto.setBackground(new java.awt.Color(255, 255, 255));
        jBtnFoto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/picture.png"))); // NOI18N
        jBtnFoto.setText("FOTO DEL CLIENTE");
        jBtnFoto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnFotoActionPerformed(evt);
            }
        });

        jLabel23.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel23.setText("Codigo:");

        jLabel25.setText("* E - Mail:");

        jLabel15.setText("*Direccion");

        jLabel9.setForeground(new java.awt.Color(255, 0, 0));

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/tango-clear.png"))); // NOI18N
        jButton4.setText("LIMPIAR CAMPOS");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel1.setText("Apellido");

        javax.swing.GroupLayout jPanelTransparente5Layout = new javax.swing.GroupLayout(jPanelTransparente5);
        jPanelTransparente5.setLayout(jPanelTransparente5Layout);
        jPanelTransparente5Layout.setHorizontalGroup(
            jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTransparente5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelTransparente5Layout.createSequentialGroup()
                        .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelTransparente5Layout.createSequentialGroup()
                                .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanelTransparente5Layout.createSequentialGroup()
                                        .addComponent(jLabel23)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE))
                                    .addComponent(jLabel15)
                                    .addGroup(jPanelTransparente5Layout.createSequentialGroup()
                                        .addComponent(jLabel10)
                                        .addGap(6, 6, 6)
                                        .addComponent(jTxtTelefono, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE))
                                    .addGroup(jPanelTransparente5Layout.createSequentialGroup()
                                        .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel12)
                                            .addComponent(jLabel13)
                                            .addComponent(jLabel1))
                                        .addGap(17, 17, 17)
                                        .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jTxtNombre, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
                                            .addComponent(jTxtApellido, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
                                            .addComponent(jTcedula, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
                                            .addComponent(jTxDireccion, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)))
                                    .addGroup(jPanelTransparente5Layout.createSequentialGroup()
                                        .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel14)
                                            .addComponent(jLabel25)
                                            .addComponent(jLabel16))
                                        .addGap(6, 6, 6)
                                        .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jTxtMail, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
                                            .addComponent(jTxtCelular, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
                                            .addComponent(jCbxPais, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jBtnFoto, javax.swing.GroupLayout.DEFAULT_SIZE, 169, Short.MAX_VALUE)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel22)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLblFoto, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, 641, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(jPanelTransparente5Layout.createSequentialGroup()
                        .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel19)
                            .addComponent(jLabel17))
                        .addGap(33, 33, 33)
                        .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelTransparente5Layout.createSequentialGroup()
                                .addComponent(jCbxProvincia, 0, 246, Short.MAX_VALUE)
                                .addGap(329, 329, 329))
                            .addGroup(jPanelTransparente5Layout.createSequentialGroup()
                                .addComponent(jCBCiudad, javax.swing.GroupLayout.PREFERRED_SIZE, 247, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addContainerGap())))))
        );
        jPanelTransparente5Layout.setVerticalGroup(
            jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTransparente5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel23)
                    .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(1, 1, 1)
                .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jTxtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLblFoto, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanelTransparente5Layout.createSequentialGroup()
                        .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanelTransparente5Layout.createSequentialGroup()
                                .addComponent(jLabel22)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane1))
                            .addGroup(jPanelTransparente5Layout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel1)
                                    .addComponent(jTxtApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel12)
                                    .addComponent(jTcedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel15)
                                    .addComponent(jTxDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel10)
                                    .addComponent(jTxtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(11, 11, 11)
                                .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel14)
                                    .addComponent(jTxtCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jBtnFoto, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jTxtMail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel25)))
                        .addGap(18, 18, 18)
                        .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel16)
                            .addComponent(jCbxPais, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel17)
                            .addComponent(jCbxProvincia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanelTransparente5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCBCiudad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel19))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTable1.setModel(modeloTabla1);
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(jTable1);

        jBSalir1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Desktop 2.png"))); // NOI18N
        jBSalir1.setText("SALIR");
        jBSalir1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSalir1ActionPerformed(evt);
            }
        });

        jBActualizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/refresh.png"))); // NOI18N
        jBActualizar.setText("ACTUALIZAR");
        jBActualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBActualizarActionPerformed(evt);
            }
        });

        ListSelectionModel ls =  jTable1.getSelectionModel();
        ls.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                try{
                    if(e.getValueIsAdjusting())return;
                    ListSelectionModel lsss=(ListSelectionModel )e.getSource();
                    if(lsss.isSelectionEmpty()){
                    }else{
                        condicion=true;
                    }
                }catch(Exception z){
                }
            }
        });
        jBModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/edit.png"))); // NOI18N
        jBModificar.setText("MODIFICAR");
        jBModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBModificarActionPerformed(evt);
            }
        });

        ListSelectionModel lssms =  jTable1.getSelectionModel();
        lssms.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                try{
                    if(e.getValueIsAdjusting())return;
                    ListSelectionModel lss=(ListSelectionModel )e.getSource();
                    if(lss.isSelectionEmpty()){
                    }else{
                        condicion=true;
                    }
                }catch(Exception z){
                }
            }
        });
        jBEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/stop.png"))); // NOI18N
        jBEliminar.setText("ELIMINAR");
        jBEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBEliminarActionPerformed(evt);
            }
        });

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Floppy.png"))); // NOI18N
        jButton1.setText("REGISTRAR");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        JBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/search.png"))); // NOI18N
        JBuscar.setText("BUSCAR");
        JBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JBuscarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelTransparente6Layout = new javax.swing.GroupLayout(jPanelTransparente6);
        jPanelTransparente6.setLayout(jPanelTransparente6Layout);
        jPanelTransparente6Layout.setHorizontalGroup(
            jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTransparente6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JBuscar, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                    .addComponent(jBActualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 195, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBModificar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                    .addComponent(jBEliminar, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                    .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
                    .addComponent(jBSalir1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanelTransparente6Layout.setVerticalGroup(
            jPanelTransparente6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTransparente6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jBActualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(JBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jBModificar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jBEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jBSalir1, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(40, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 886, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanelTransparente5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanelTransparente6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanelTransparente6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelTransparente5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jMenu1.setText("Operaciones");
        jMenu1.add(jSeparator1);

        jMenuItem8.setText("Salir");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem8);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edicion");

        jMenuItem1.setText("Copiar");
        jMenu2.add(jMenuItem1);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
        // Salir
        this.dispose();
    }//GEN-LAST:event_jMenuItem8ActionPerformed

    private void jTxtNombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTxtNombreActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_jTxtNombreActionPerformed

    private void jCbxPaisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCbxPaisActionPerformed
            // Pais
        jCbxProvincia.removeAllItems();
        jCBCiudad.removeAllItems();
        if(jCbxPais.getSelectedIndex()!=0){
            String nombre = ""+jCbxPais.getSelectedItem();
            Pais ps = Mu.Consultar(nombre);

            for(int x=0; x<ps.getProvincia().size();x++){
                  jCbxProvincia.addItem(ps.getProvincia().get(x).getNombre());

        }

       }
}//GEN-LAST:event_jCbxPaisActionPerformed

    private void jBtnFotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnFotoActionPerformed
        JFileChooser dlg = new JFileChooser();
        //Abre la ventana de dialogo
        int option = dlg.showOpenDialog(this);
        //Si hace click en el boton abrir del dialogo
        if(option==JFileChooser.APPROVE_OPTION) {
            //Obtiene nombre del archivo seleccionado
            String file = dlg.getSelectedFile().getPath();
            jLblFoto.setIcon(new ImageIcon(file));
            //Modificando la imagen
            ImageIcon icon = new ImageIcon(file);
            //Se extrae la imagen del icono
            Image img = icon.getImage();
            //Se modifica su tamaño
            Image newimg = img.getScaledInstance(140,170,java.awt.Image.SCALE_SMOOTH);
            //SE GENERA EL IMAGE ICON CON LA NUEVA IMAGEN
            ImageIcon newIcon = new ImageIcon(newimg);
            //Se coloca el nuevo icono modificado
            jLblFoto.setIcon(newIcon);
            //Se cambia el tamaño de la etiqueta
            jLblFoto.setSize(470,290);
        }
}//GEN-LAST:event_jBtnFotoActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // LimpiarCampos
        this.BorrarCampos();
}//GEN-LAST:event_jButton4ActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked

        int posicionn=this.jTable1.getSelectedRow();
        Cliente cl = new Cliente();
        cl = Mc.getListacliente().get(posicionn);
        this.mostrar(cl);

    }//GEN-LAST:event_jTable1MouseClicked

    private void jBSalir1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSalir1ActionPerformed
        // Cerramos esta ventana
          this.dispose();
}//GEN-LAST:event_jBSalir1ActionPerformed

    private void jBActualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBActualizarActionPerformed
        // Actualizar ó cancelar
        this.Actualizar();
}//GEN-LAST:event_jBActualizarActionPerformed

    private void jBModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBModificarActionPerformed
     //Modificar Cliente
        if(jBModificar.getText().equals("MODIFICAR")){
                if(condicion==true){
                    this.ActivarCampos();
                    cl=Mc.getListacliente().get(jTable1.getSelectedRow());;
                    mostrar(cl);
                    jBModificar.setText("GUARDAR");
                    ImageIcon[] img_Btns = new ImageIcon[8];
                    img_Btns[0] = new ImageIcon(getClass().getResource(""
                            + "/Imagenes/Floppy.png"));
                    jBModificar.setIcon(img_Btns[0]);
                    jBActualizar.setText("CANCELAR");
                    JOptionPane.showMessageDialog(null, "Se han activado "
                            + "los campos para su edicion");
                }else{
                     ced = JOptionPane.showInputDialog("Digite cedula del cliente");

                    if(ced!=null){
                        cl = Mc.Consultar(ced);
                        
                        if(cl.getCedula()==null){
                            JOptionPane.showMessageDialog(null, "Este cliente "
                                    + "no existe");
                        } else {
                            this.mostrar(cl);
                            this.ActivarCampos();
                               jBModificar.setText("GUARDAR");
                                ImageIcon[] img_Btns = new ImageIcon[8];
                                img_Btns[0] = new ImageIcon(getClass().
                                        getResource("/Imagenes/Floppy.png"));
                                jBModificar.setIcon(img_Btns[0]);
                                jBActualizar.setText("CANCELAR");
                                JOptionPane.showMessageDialog(null, "Se"
                                 + " han activado los campos para su edicion");                               
                        }
                     }
                }
                vc.add(cl);
        }else{

            Cliente cll = new Cliente();
            cll.setCodigo(jLabel9.getText());
            cll.setNombre(jTxtNombre.getText());
            cll.setApellido(jTxtApellido.getText());
            cll.setDireccion(jTxDireccion.getText());
            cll.setCedula(jTcedula.getText());
            cll.setTelefono(jTxtTelefono.getText());
            cll.setCelular(jTxtCelular.getText());
            cll.setEmail(jTxtMail.getText());
            cll.setFoto(jLblFoto.getIcon());
            cl=vc.get(0);
            Mc.Modificar(cl.getCedula(), cll);
            this.Actualizar();

        }

        this.condicion = false;

    }//GEN-LAST:event_jBModificarActionPerformed

    private void jBEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBEliminarActionPerformed
        // Eliminar
        
            if(condicion==true){
            int question = JOptionPane.showConfirmDialog(null,"¿Seguro que desea"
                    + " eliminar este cliente?","Informacion",JOptionPane.YES_NO_OPTION);
            if(question==0){
                int posicion=this.jTable1.getSelectedRow();
                c = Mc.getListacliente().get(posicion);
                modeloTabla1.removeRow(posicion);
                Mc.Eliminar(c.getCedula());
            }else{
                JOptionPane.showMessageDialog(null, "Peticion ca"
                        + "ncelada","Informacion",JOptionPane.INFORMATION_MESSAGE);
            }

        }else{
                 String ced = JOptionPane.showInputDialog("Digite cedula del "
                         + "cliente");

                    if(ced!=null){
                        c = Mc.Consultar(ced);
                        if(c.getCedula().equals("")){
                            JOptionPane.showMessageDialog(null, "Este cliente "
                                    + "no existe");
                        } else {

                            int posi = Mc.Posicion(c.getCedula());
                            modeloTabla1.removeRow(posi);
                            Mc.Eliminar(c.getCedula());

                        }


                 }
        }

 this.condicion = false;
       
}//GEN-LAST:event_jBEliminarActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        //Registrar
        if(jButton1.getText().equals("Guardar")){

            Cliente cl = new Cliente();
            cl.setCodigo(jLabel9.getText());
            cl.setNombre(jTxtNombre.getText());
            cl.setApellido(jTxtApellido.getText());
            cl.setDireccion(jTxDireccion.getText());
            cl.setCedula(jTcedula.getText());
            cl.setTelefono(jTxtTelefono.getText());
            cl.setCelular(jTxtCelular.getText());
            cl.setEmail(jTxtMail.getText());
            cl.setFoto(jLblFoto.getIcon());
            Mc.Registrar(cl);
            this.Actualizar();


        }else{
            this.ActivarCampos();
            this.jLabel9.setVisible(true);
            this.jButton1.setText("Guardar");
            this.jBActualizar.setText("Cancelar");
            ImageIcon[] img_Btns = new ImageIcon[8];
            img_Btns[0] = new ImageIcon(getClass().getResource("/Imagenes/"
                    + "stop_alt.png"));
            jBActualizar.setIcon(img_Btns[0]);
            this.Limpiar_Entradas();
            this.jLabel9.setText(this.Mc.GenerarCodigo()+"");
        }

        
}//GEN-LAST:event_jButton1ActionPerformed

    private void JBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JBuscarActionPerformed
        // Buscar proveedor especificamente

        String c = JOptionPane.showInputDialog("Digite cedula del cliente "
                + "a buscar");
        Cliente cl= Mc.Consultar(c);
        if(cl.getCedula().equals("")){
            JOptionPane.showMessageDialog(null, "cliente no Encontrado");
        }else{
            this.mostrar(cl);
        }
        
        estado=true;
}//GEN-LAST:event_JBuscarActionPerformed

    private void jCbxProvinciaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCbxProvinciaActionPerformed
              // Ciudades
          if(jCbxPais.getSelectedIndex()!=0){
            String nombre = ""+jCbxPais.getSelectedItem();
            String nombreprovinia = jCbxProvincia.getSelectedItem()+"";
            Pais ps = Mu.Consultar(nombre);
            Provincia pro = ps.getProvincia().get(this.Posicion(nombreprovinia, ps.getProvincia()));

            for(int x=0;x<pro.getCiudad().size();x++){
               Ciudad c =(Ciudad) pro.getCiudad().get(x);
               jCBCiudad.addItem(c.getNombre());
            }

        }
    }//GEN-LAST:event_jCbxProvinciaActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {

       try {
             javax.swing.UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
             LiquidLookAndFeel.setLiquidDecorations(true, "mac");

}
catch (Exception e) {}

        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VistaCliente().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton JBuscar;
    private javax.swing.JButton jBActualizar;
    private javax.swing.JButton jBEliminar;
    private javax.swing.JButton jBModificar;
    private javax.swing.JButton jBSalir1;
    private javax.swing.JButton jBtnFoto;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton4;
    private javax.swing.JComboBox jCBCiudad;
    private javax.swing.JComboBox jCbxPais;
    private javax.swing.JComboBox jCbxProvincia;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLblFoto;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JPanel jPanel1;
    private Imagenes.JPanelTransparente jPanelTransparente5;
    private Imagenes.JPanelTransparente jPanelTransparente6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTcedula;
    private javax.swing.JTextField jTxDireccion;
    private javax.swing.JTextArea jTxaObs;
    private javax.swing.JTextField jTxtApellido;
    private javax.swing.JTextField jTxtCelular;
    private javax.swing.JTextField jTxtMail;
    private javax.swing.JTextField jTxtNombre;
    private javax.swing.JTextField jTxtTelefono;
    // End of variables declaration//GEN-END:variables


   
  private void seguro() {
    int salir=JOptionPane.showConfirmDialog(null, "¿Desea Registra "
            + "otro Cliente?","Cerrar",JOptionPane.YES_NO_OPTION);
    if(salir ==1){
         this.dispose();
    }
    }

    private void mostrar(Cliente cl) {

        this.jTxtNombre.setText(cl.getNombre());
        this.jTxtApellido.setText(cl.getApellido());
        this.jTcedula.setText(cl.getCedula()+"");
        this.jTxDireccion.setText(cl.getDireccion());
        this.jTxtTelefono.setText(cl.getTelefono());
        this.jTxtMail.setText(cl.getEmail());
        this.jTxtCelular.setText(cl.getCelular());        
        this.jLblFoto.setIcon(cl.getFoto());
        this.jLabel9.setText(cl.getCodigo());
        this.jTxaObs.setText(cl.getDetalle());
    }

    private void BorrarCampos() {

        this.jTxtNombre.setText("");
        this.jTxtTelefono.setText("");
        this.jTxtMail.setText("");
        this.jTxDireccion.setText("");
        this.jTxtCelular.setText("");
        this.jTxaObs.setText("");
        this.jLblFoto.setIcon(null);
        this.jLabel9.setText("");
        this.jTxtApellido.setText("");
        this.jTcedula.setText("");
    }


    private void ActivarCampos() {

        this.jTxtNombre.setEditable(true);
        this.jTxtTelefono.setEditable(true);
        this.jTxtMail.setEditable(true);
        this.jTxDireccion.setEditable(true);
        this.jTxtCelular.setEditable(true);
        this.jTxaObs.setEditable(true);
        this.jBtnFoto.setEnabled(true);
        this.jTxtApellido.setEditable(true);
        this.jTcedula.setEditable(true);
        this.jCbxProvincia.setEnabled(true);
        this.jCbxPais.setEnabled(true);
        this.jCBCiudad.setEnabled(true);
    }

    private void DesactivarCampos() {
        this.jTxtNombre.setEditable(false);
        this.jTxtTelefono.setEditable(false);
        this.jTxtMail.setEditable(false);
        this.jTxDireccion.setEditable(false);
        this.jTxtCelular.setEditable(false);
        this.jTxaObs.setEditable(false);
        this.jTcedula.setEditable(false);
        this.jTxtApellido.setEditable(false);
        this.jBtnFoto.setEnabled(false);
        this.jCBCiudad.setEnabled(false);
        this.jCbxPais.setEnabled(false);
        this.jCbxProvincia.setEnabled(false);

    }

    private void desactivarBotones() {
//        this.jButton5.setEnabled(false);
//        this.JBbuscar.setText("CANCELAR");
//        ImageIcon icon = new ImageIcon("Imagenes/icon_cancel.png");
//        this.JBbuscar.setIcon(icon);

    }

    private void Registrar() {

        Cliente c = new Cliente();
        c.setNombre(jTxtNombre.getText());
        c.setApellido(jTxtApellido.getText());
        c.setDireccion(jTcedula.getText());
        c.setCedula(jTxDireccion.getText());
        c.setTelefono(jTxtTelefono.getText());
        c.setEmail(jTxtMail.getText());
        c.setCelular(jTxtCelular.getText());
        if(jLblFoto.getIcon()!=null){
            c.setFoto(jLblFoto.getIcon());
        }
        c.setDetalle(jTxaObs.getText());

        Mc.Registrar(c);
        try {
            Mc.grabar();
        } catch (IOException ex) {
            Logger.getLogger(VistaCliente.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void Actualizar(){

        this.dispose();
        VistaCliente Vc = new VistaCliente(Mc,Mu);
        Vc.setLocationRelativeTo(null);
        Vc.setVisible(true);

    }

    private void Limpiar_Entradas() {

        jLabel9.setText("");
        jTxtNombre.setText("");
        jTxtApellido.setText("");
        jTcedula.setText("");
        jTxDireccion.setText("");
        jTxtTelefono.setText("");
        jTxtCelular.setText("");
        jTxtMail.setText("");
        jLblFoto.setIcon(null);
        jTxtNombre.requestFocus();


    }

        public int Posicion(String nombre,List<Provincia> pro){
            Provincia p;
          Iterator itc=pro.iterator();
          int pos=-1;
          int ind=-1;
         while(itc.hasNext()){
             p = (Provincia)itc.next();
            if(p.getNombre().equals(nombre)){
                ind=ind+1;
                 pos=ind;
            }else{
                ind=ind+1;
            }
         }
          return pos;
    }

    private void TablaPrincipal() {
        modeloTabla1.addColumn("Nombre");
            modeloTabla1.addColumn("Apellido");
            modeloTabla1.addColumn("Cedula");
            modeloTabla1.addColumn("Direccion");
            modeloTabla1.addColumn("Telefono");
            modeloTabla1.addColumn("Celular");
            modeloTabla1.addColumn("Email");


             for(int a=0;a<this.Mc.getListacliente().size();a++){
                Vector<String> vc=new Vector<String>();
                c = this.Mc.getListacliente().get(a);
                vc.add(c.getNombre());
                vc.add(c.getApellido());
                vc.add(""+c.getCedula());
                vc.add(c.getDireccion());
                vc.add(c.getTelefono());
                vc.add(c.getCelular());
                vc.add(c.getEmail());
                modeloTabla1.addRow(vc);
            }
    }

    private void JcomboPais() {
              jCbxPais.addItem("---Seleccion---");
        for(int x=0;x<Mu.getPaises().size();x++){
            jCbxPais.addItem(Mu.getPaises().get(x).getNombre());
        }
    }


}

